#include <string.h>
#include "hamilton.h"


intArray eulerToHamilton(intArray eulerCycle, int numNodes) {
	intArray result = intArray_new();
	byte*	visited = new(byte, numNodes);
	int i, n;

	memset(visited, 0, numNodes * sizeof(byte));
	

	for (i = 0; i < eulerCycle.length; ++i) {
		n = eulerCycle.data[i];
		assert (n >= 0 && n < numNodes);
		
		if (!visited[n]) {
			intArray_append(&result, n);
			visited[n] = 1;
		}
	}

	free(visited);
	visited = null;

	if (eulerCycle.length > 0) {
		intArray_append(&result, eulerCycle.data[0]);
	}

	return result;
}
